package org.shangrila.demo.pf.mb;

import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Named;

import org.primefaces.PrimeFaces;
import org.primefaces.context.RequestContext;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.primefaces.event.SelectEvent;

@Named(value="dfView")
@SessionScoped
public class DFView {
    private List<DemoOperator> opers;
    
    public List<DemoOperator> getOpers() {
		return opers;
	}

	public void setOpers(List<DemoOperator> opers) {
		this.opers = opers;
	}
	
	@PostConstruct
	public void init() {
    	opers=new ArrayList<DemoOperator>();
    	opers.add(new DemoOperator("11","hello"));
    	opers.add(new DemoOperator("12","world"));
    	opers.add(new DemoOperator("21","say"));
    	opers.add(new DemoOperator("22","goodbye"));
    	opers.add(new DemoOperator("31","sayonana"));
    	opers.add(new DemoOperator("33","cacaca"));    	
	}

	public void chooseOper() {
        Map<String,Object> options = new HashMap<String, Object>();
        options.put("resizable", false);
        options.put("draggable", false);
        options.put("modal", true);
        PrimeFaces.current().dialog().openDynamic("pf-dialog-data-select", options, null);
    }
     
    public void onOperChosen(SelectEvent event) {
    	DemoOperator oper = (DemoOperator) event.getObject();
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Oper Selected", "Id:" + oper.getUsername());
         
        FacesContext.getCurrentInstance().addMessage(null, message);
    }
    
    public void selectOperFromDialog(DemoOperator oper) {
        PrimeFaces.current().dialog().closeDynamic(oper);
    }

}